home *** CD-ROM | disk | FTP | other *** search
- <html>
-
- <head>
-
- <title>Playing With The Layers Array</title>
-
- </head>
-
- <script language="JavaScript1.2">
-
- <!--//
-
-
-
- var currentLayer;
-
-
-
- //-------loadLayer function--------
-
- //this function populates a <select> input box with the array of layers on the page...
-
-
-
- function loadLayers(obj) {
-
- var n = 0;
-
- var el;
-
- for(n=1;n<document.layers.length;n++) {
-
- el = new Option('document.layers[' + n + ']', n);
-
- obj.mylayers.options[n] = el;
-
- }
-
- }
-
-
-
- //-------getLayer function--------
-
- //if you've selected a layer from the select list (mylayers) this function populates
-
- //the form with information about the layer, then moves the layer into the table
-
- //for your inspection and manipulation...
-
-
-
- function getLayer(obj) {
-
- if (obj.mylayers.selectedIndex > 0) {
-
- var selLayer = obj.mylayers.options[obj.mylayers.selectedIndex].value;
-
- if ((currentLayer != selLayer) && (currentLayer)) {
-
- document.layers[currentLayer].left = (20 + ((currentLayer -1) * 40));
-
- document.layers[currentLayer].top = 10;
-
- document.layers[currentLayer].width = 40;
-
- }
-
- currentLayer = selLayer;
-
- document.layers[currentLayer].left = 380;
-
- document.layers[currentLayer].top = 113;
-
- obj.layername.value = document.layers[currentLayer].id;
-
- } else {
-
- alert('No Layer Selected!');
-
- }
-
- }
-
-
-
-
-
-
-
- //-------getValue function--------
-
- //if you're looking at a layer, the JavaScript statement in the control box has a
-
- //dropdown list of several layer properties. Selecting one of them will auto-fill
-
- //that attribute's property in the form...
-
-
-
- function getValue(obj) {
-
- if (currentLayer) {
-
- var gv = obj.att.options[obj.att.options.selectedIndex].value
-
- var cl = document.layers[currentLayer]
-
- if (gv == 'top') obj.setting.value = cl.top;
-
- if (gv == 'left') obj.setting.value = cl.left;
-
- if (gv == 'visibility') obj.setting.value = cl.visibility;
-
- if (gv == 'src') obj.setting.value = cl.src;
-
- } else {
-
- alert('No Layer Was Selected!');
-
- }
-
- }
-
-
-
- //-------resetLayers function--------
-
- //this just clears the form, and moves all layers back to their original positions...
-
-
-
- function resetLayers(obj) {
-
- if (currentLayer) {
-
- document.layers[currentLayer].left = (20 + ((currentLayer -1) * 40));
-
- document.layers[currentLayer].top = 10;
-
- document.layers[currentLayer].width = 40;
-
- currentLayer = null;
-
- obj.layername.value = '';
-
- obj.setting.value = '';
-
- obj.att.options[0].selected = true;
-
- } else {
-
- alert('No Active Layer Selected!');
-
- }
-
- }
-
-
-
- //-------setValue function--------
-
- //once you're viewing a layer, and have selected an attribute, you can change its value
-
- //and click the 'set' button to assign that value to the selected property. Keep in mind
-
- //that the page is showing the actual JavaScript syntax that could be run to control that
-
- //selected layer...
-
-
-
- function setValue(obj) {
-
- if ((currentLayer) && (obj.setting.value != '')){
-
- var gv = obj.att.options[obj.att.options.selectedIndex].value;
-
- var cl = document.layers[currentLayer];
-
- if (gv == 'top') cl.top = obj.setting.value;
-
- if (gv == 'left') cl.left = obj.setting.value;
-
- if (gv == 'visibility') cl.visibility = obj.setting.value;
-
- if (gv == 'src') cl.src = obj.setting.value;
-
- } else {
-
- alert('No Layer or Attribute Was Selected!');
-
- }
-
- }
-
-
-
- //-->
-
- </script>
-
- <body bgcolor="white">
-
- <layer z-index=1 id="redblock" width=40 bgcolor="red" top=10 left=20><h1>[1]</h1></layer>
-
- <layer z-index=2 id="blueblock" width=40 bgcolor="blue" top=10 left=60><h1>[2]</h1></layer>
-
- <layer z-index=3 id="silverblock" width=40 bgcolor="silver" top=10 left=100><h1>[3]</h1></layer>
-
- <layer z-index=4 id="yellowblock" width=40 bgcolor="yellow" top=10 left=140><h1>[4]</h1></layer>
-
- <layer z-index=5 id="greenblock" width=40 bgcolor="green" top=10 left=180><h1>[5]</h1></layer>
-
- <layer z-index=0 name="control" width=550 height=70 left=20 top=65>
-
- <form>
-
- <table width=550>
-
- <tr><td colspan=3 align=center>
-
- <b>Control Center</b> ( document.layers[0] )
-
- </td></tr>
-
- <tr><td valign=top width=150>
-
- <select name="mylayers" size=6>
-
- <option value="">----Layers Array----
-
- </select>
-
- </td><td valign=middle align=center width=100>
-
- <input type="button" value="Load Array" onClick="loadLayers(this.form)">
-
- <input type="button" value="Properties " onClick="getLayer(this.form)">
-
- <input type="button" value=" Reset " onClick="resetLayers(this.form)">
-
- </td><td bgcolor="black" width=250>
-
-
-
- </td></tr>
-
- <tr><td align=center valign=top colspan=3 width=500>
-
- <br>
-
- <tt>document.layers['<input type="text" name="layername"
-
- size=12>']</tt>.<select name="att" onChange="getValue(this.form)">
-
- <option value="">
-
- <option value="top">top
-
- <option value="left">left
-
- <option value="visibility">visibility
-
- <option value="src">src
-
- </select> = <input type="text" size=15 name="setting">
-
- <input type=button value="set" onClick="setValue(this.form)"><br>
-
- </table>
-
- </form>
-
- </layer>
-
- </body>
-
- </html>
-
-